<?php


/**
 * 用戶管理Model
 * Enter description here ...
 * @author Admin
 *
 */
class UserModel extends CommonModel {
	
	/**
	 * 字段映射
	 * Enter description here ...
	 * @var unknown_type
	 */
	protected $_map = array(
		'userEmail'=>'mail',
		'userNickname'=>'name',
		'userPassword'=>'password',
		'photo'=>'head',
		'phoneno'=>'tel',
	);
	
	
	/**
	 * 自动验证
	 * Enter description here ...
	 * @var unknown_type
	 */
	protected $_validate	 =	 array(
		array('mail','require','邮箱必须！'),
		array('mail','email','邮箱格式不正确！'),
		array('mail','','邮箱必须唯一！',0,'unique',1),
		array('name','require','昵称必须！'),
		array('name','','昵称必须唯一！',0,'unique',1),
		array('ip','/\d+\.\d+\.\d+\.\d+/','IP格式不正确！',2),
		array('tel','/\d{11}|\d{4}-[\d{7}|\d{8}]/','联系方式格式不正确！',2),
	);
	
	
	
	/**
	 * 自动填充
	 * Enter description here ...
	 * @var unknown_type
	 */
	protected $_auto = array ( 
		array('state','0'),      // 新增的时候把state字段设置为1
		array('password','md5',3,'function') , // 对password字段使md5函数处理
		array('head','sub_head',3,'function') , 
		array('birthday','strtotime',3,'function'), 
		array('addtime','time',1,'function'), // 对addtime字段在更新的时候写入当前时间戳
	);
	
	
	
	
	
	/**
	 * 根据邮箱重置用户密码
	 * Enter description here ...
	 * @param unknown_type $mail
	 */
	public function setpwd($mail){
		$string = rand_string(9);
		$map['mail'] = array('eq',$mail);
		$this->where($map)->setField('password',md5($string));
		
		return $string;
	}
	

	
	
	/**
	 * 设置实体竞标币
	 * Enter description here ...
	 * @param unknown_type $uid
	 * @param unknown_type $beat
	 */
	public function _setbeat($uid,$beat){
		$prefix = C('DB_PREFIX');
		$sql = "UPDATE {$prefix}user SET `beat` = `beat` + {$beat} WHERE id = {$uid}";
		$this->query($sql);
	}
	
	
	
	/**
	 * 设置虚拟竞标币
	 * Enter description here ...
	 * @param unknown_type $uid
	 * @param unknown_type $pointb
	 */
	public function _setpointb($uid,$pointb){
		$prefix = C('DB_PREFIX');
		$sql = "UPDATE {$prefix}user SET `pointb` = `pointb` + {$pointb} WHERE id = {$uid}";
		$this->query($sql);
	}
	
	
	
	
	
	
}
?>